package com.itheima.ssm.dao;

import com.itheima.ssm.domain.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface IPermissionDao {

    //根据roleid查询出所有的Permission
    @Select("select * from permission where id in (select permissionId from role_permission where roleId = #{id} )")
    List<Permission> findPermissionByRoleId(String id) throws Exception;

    //查询所有的资源权限
    @Select("select * from permission")
    List<Permission> findAll();

    //    添加权限
    @Insert("insert into permission(permissionName,url) values(#{permissionName},#{url})")
    void save(Permission permission) throws Exception;

    //根据资源id查询资源详情
    @Select("select * from permission where id =#{id}")
    Permission findById(String id) throws Exception;

    //    根据id删除中间表
    @Delete("delete  from role_permission where permissionId =#{id}")
    void deleteFromRoel_Permission(String id) throws Exception;

    //   根据id删除资源权限表
    @Delete("delete  from permission where id = #{id}")
    void deleteFromPermission(String id) throws Exception;
}
